<template>
    <div class="header">
        <router-link class="header-abs" to="/" v-show="showAbs">
            <span class="iconfont back-icon">&#xe624;</span>
        </router-link>
        <div class="header-fixed" v-show="!showAbs" :style="style">
            <router-link to="/">
                <span class="iconfont back-icon">&#xe624;</span>
            </router-link>
            景点详情
        </div>
    </div>
</template>

<script>
    export default {
        data() {
            return {
                showAbs:true,
                style:{
                    opacity:0
                }
            }
        },
        methods: {
            // header渐隐渐现效果
            handleScroll(){
                let height=document.documentElement.scrollTop
                if(height>60){
                    let opacity=height/140
                    this.style.opacity=opacity>1?1:opacity
                    this.showAbs=false
                }else{
                    this.showAbs=true
                }
            },
        },
        activated() {
            window.addEventListener('scroll',this.handleScroll)
        },
        deactivated() { //在组件关闭前执行
            // 解除全局绑定滑动问题
            window.removeEventListener('scroll',this.handleScroll)
        },
    }
</script>

<style lang="stylus" scoped>
@import '~@/assets/css/global.styl'
.header
    .header-abs
        position absolute
        left .2rem
        top .2rem
        width .8rem
        height .8rem
        line-height .8rem
        border-radius .4rem
        background rgba(0,0,0,.8)
        .back-icon
            display block
            color #fff
            font-size .4rem
            text-align center
    .header-fixed
        position fixed
        top 0
        right 0
        left 0
        height $headerHeight
        line-height $headerHeight
        text-align center
        color #fff
        background $bgColor
        font-size .32rem
        z-index 1
        .back-icon
            position absolute
            top 0
            left 0
            width .64rem
            text-align center
            font-size .4rem
            color #fff
</style>